home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
xlib.zip
/
XLIB.MAN
< prev
Wrap
Text File
|
1987-07-12
|
16KB
|
529 lines
Communications and Multitasking Library
For Datalight C
by
Matt Brandt
Overview
This library contains a multitasking kernel and a
communications kernel. The communications kernel allows you
to control the com ports of a PC in a simple way but allows
any speed the com port is capable of running. The
communications routines are interrupt driven so that even in
very fast transfers a program will not have any trouble
keeping up. The multitasking kernel allows a program to have
several apparently simultaneous execution threads. This is
especially usefull in communications because there is
usually traffic in both directions. A small terminal program
"mini.c" is included in this archive to demonstrate the
concepts. While you may use the communications routines
without worring about the multitasking I urge you to take
the time to understand the multasking kernel. It will make
your life much easier for many applications, not just
communications. In the following pages I will discuss the
concepts of the communications and multitasking routines and
demonstrate how each routine is called. The last section
deals with the example program mini.c and shows how it
works.
This package is being distributed as shareware. You may try
it out, see if it is what you want, and if it fits a need
you have then I ask that you send me 20 dollars. For your
twenty dollars you will get the complete source code, a
license to use any and all of these routines in your own
code for profit without any royalties, and the other three
models (P,D, and L) of the library. If you do not need this
package and do not use it then you are under no obligation
to send me any money. Please feel free to pass this archive
on in it's original form to friends and BBS's that you think
might be interested.
If you want to send in a contribution send your check to:
Matt Brandt
PO Box 920337
Norcross, GA 30092
Your comments and suggestions are also welcome.
Multitasking Concepts
This library implements what is called a non-preemptive
scheduler. This means that when one task is running it will
not be "preempted" by a task of higher priority. A task is
only suspended when it makes one of two tasking calls. It is
up to the programmer to make sure that all tasks get a
chance to run. Each task has it's own stack area. The global
and static data of the program is available to all tasks.
The task scheduler does not "hook" any interrupts or take
over any of the machine resources so any task can return to
DOS at any time. This will have the effect of killing all of
the other tasks.
There can be up to 32 seperate tasks. The main program is
assigned task number zero at program startup. The tasks are
prioritized by task number with task zero being the highest
priority task and task 31 being the lowest priority. You do
not need to assign task numbers sequentially. It is
perfectly acceptable to have only tasks zero and ten for
instance. The scheduler will perform slightly better,
however, when there are a minimum number of "holes" in the
task assignments.
Tasks can syncronize and communicate through signals. It is
also possible for interrupt service routines to send signals
to tasks. There are 32 signals available [0..31]. Any task
can wait for a signal. It will then be suspended until that
signal is sent by another task or an interrupt routine. If a
signal is sent and there is nobody waiting for it then it
will be saved until the next wait is performed. That wait
will not suspend the task but instead will receive the
signal that was previously sent. Only one occurance of each
signal can be saved. Multiple unwaited occurrances are the
same as one unwaited occurrance. More that one task may wait
for a given signal. In this case the highest priority
waiting task will be readied when the signal is sent.
The task calls are as follows:
t_create(tasknum,func,stk,stksiz);
int tasknum;
void (*func)();
int *stk;
int stksiz;
This call creates a task whose task number is given by
tasknum. If a task is already running at that task
number it is replaced by the new task. func should be
the address of a function to be executed as the new
task. stk should point to an area of memory and stksiz
should be the size of the task's stack area in bytes.
If a task function returns the task is deleted. The new
task is placed in a ready to run state but is not given
control until scheduling occurs by way of a t_wait or
t_yield call. If the new task number is the same as the
currently running task then this call will have no
effect.
EXAMPLE:
int t1stk[512];
task1()
{
..code to do a job
}
.
t_create(1,task1,t1stk,sizeof(t1stk));
t_kill(tasknum)
int tasknum;
This call will delete the task whose task number is
given by tasknum. If tasknum matches the task number of
the currently running task the current task will be
killed and rescheduling will occur.
t_wait(signo)
int signo;
The task issuing this call will wait until signal
number signo is issued by another task or an interrupt
service routine. If the signal was already issued then
the current task will continue unhindered. When a task
suspends then the highest priority ready task is
continued at the point where it left off.
t_signal(signo)
This call causes an occurrance of signal number signo.
The highest priority task waiting for that signal will